
<!-- 公共头部 --> 
<include file="Base:header" />
    
    <!-- 公共头部 --> 
    <style>
.cke_toolbox_collapser.cke_toolbox_collapser_min{
							display:none;
						}
	#select { width:168px; height:16px; background:none; border:none;border:solid 1px #121212;border-radius:10px; } 
	/*#sleHid { display:block; width:143px; overflow:hidden; } */
	/*#sele_id { width:168px; height:16px; border: 1px solid #A3938C; background:url("icon3.jpg") #fff no-repeat 151px 0px; display:block;} */
</style> 
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/home/css/article.css" /> 
    <div class="atl-add-bg pb-mt40"> 
     <div class="atl-add-head pb-main"> 
      <h3>好文章好分享,期待你的作品</h3> 
      <p>随心去飘吧，世界的大不是你能想象的。感悟不同文化，见识不同的事。这样的人生才不失趣味。记录你走过的地方,感悟到的文化,不同的风景,每到一个地方不同的心情 ：）</p> 
     </div> 
    </div> 
    <div class="pb-main atl-add pb-mt30"> 
     <div class="pb-inner-main"> 
       <form  id="form_ft" method="post" enctype="multipart/form-data" name='myform' class="form-horizontal"> 
        <input type="hidden" name="user_id" value="{$user['id']}"/>
	       <h3 class="pb-mt30 pb-size-big pb-clr1">标题</h3>
	       <p class="tle pb-mt10"> <input class="text-input small-input" name="title" id="EssayUser_title" type="text" maxlength="18" /> </p> 
	       <h3 class="pb-mt30 pb-size-big pb-clr1">内容</h3> 
	       <textarea  id="EssayUser_content" name="content" placeholder="内容填充区...." style="width:490px;height:150px;border:solid 1px #FAEBD7; border-radius:10px;resize:none;"></textarea>
	       <div class="form-group" style="margin-left:500px;margin-top:-178px;">
				<label class="col-md-3 control-label" for="select">选择类别</label>
				<div class="col-md-9">
					<span id="sele_id">
					<span id="sleHid">
					<select id="select" name="category_id" class="form-control" size="1">
					<foreach name="moder" item="vo">
						<option value="{$vo['id']}">{$vo['name']}</option>	
					</foreach>					
					</select>
					</span>
					</span>
				</div>
			</div>
	       <div class="form-group" style="margin-top:150px;">
                <h3 class="pb-mt10 pb-size-big pb-clr1">配图上传</h3>
                <!-- <input type="file" id="inputfile" name="img" style="position:absolute;display:none;z-index:999;"> -->
                <input type='file' id='iptfileupload' onchange='show()' name="imgs"  /><br />
               
                <!-- <img src="__PUBLIC__/admin/assets/img/{$list.img}" alt="" style="width:120px;higth:120px;"> -->
                <img src='' style="width:150px;higth:150px;margin-left:0px;" alt='' id='img' />
            </div>
	       <!-- <input id="pre-title" name="EssayUser[title]" type="hidden" /> 
	       <input id="pre-content" name="EssayUser[content]" type="hidden" />  -->
	       <p class="but pb-mt50"> <input type="button" onclick="submitPostForm();return false;" value="发布" name="submit" class="pb-button01" /> 
        <!--<input type="submit" value="预览" name="submit" class="pb-button02 pre"/>--> </p> 
      </form>
      <div id="message"  style="margin-left:115px;color:red;font-size:20px;"></div>
     </div> 
     <!-- <div class="pic"> 
      <span id="swf_EssayContent"></span> 
      <input id="btnCancel" type="button" style="display:none;" value="取消" disabled="disabled" /> 
     </div>  -->
    </div> 
    <script>
 	function getPath(obj,fileQuery,transImg) 
    {
 
           var imgSrc = '', imgArr = [], strSrc = '' ;
         
           if(window.navigator.userAgent.indexOf("MSIE")>=1){ // IE浏览器判断
            if(obj.select){
             obj.select();
             var path=document.selection.createRange().text;
             alert(path) ;
             obj.removeAttribute("src");
             imgSrc = fileQuery.value ;
             imgArr = imgSrc.split('.') ;
             strSrc = imgArr[imgArr.length - 1].toLowerCase() ;
             if(strSrc.localeCompare('jpg') === 0 || strSrc.localeCompare('jpeg') === 0 || strSrc.localeCompare('gif') === 0 || strSrc.localeCompare('png') === 0){
              obj.setAttribute("src",transImg);
              obj.style.filter=
               "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path+"', sizingMethod='scale');"; // IE通过滤镜的方式实现图片显示
             }else{
              //try{
              throw new Error('File type Error! please image file upload..'); 
              //}catch(e){
              // alert('name: ' + e.name + 'message: ' + e.message) ;
              //}
             }
            }else{
             // alert(fileQuery.value) ;
             imgSrc = fileQuery.value ;
             imgArr = imgSrc.split('.') ;
             strSrc = imgArr[imgArr.length - 1].toLowerCase() ;
             if(strSrc.localeCompare('jpg') === 0 || strSrc.localeCompare('jpeg') === 0 || strSrc.localeCompare('gif') === 0 || strSrc.localeCompare('png') === 0){
              obj.src = fileQuery.value ;
             }else{
              //try{
              throw new Error('File type Error! please image file upload..') ;
              //}catch(e){
              // alert('name: ' + e.name + 'message: ' + e.message) ;
              //}
             }
         
            }
         
           } else{
            var file =fileQuery.files[0];
            var reader = new FileReader();
            reader.onload = function(e){
         
             imgSrc = fileQuery.value ;
             imgArr = imgSrc.split('.') ;
             strSrc = imgArr[imgArr.length - 1].toLowerCase() ;
             if(strSrc.localeCompare('jpg') === 0 || strSrc.localeCompare('jpeg') === 0 || strSrc.localeCompare('gif') === 0 || strSrc.localeCompare('png') === 0){
              obj.setAttribute("src", e.target.result) ;
             }else{
              //try{
              throw new Error('File type Error! please image file upload..') ;
              //}catch(e){
              // alert('name: ' + e.name + 'message: ' + e.message) ;
              //}
             }
         
             // alert(e.target.result); 
            }
            reader.readAsDataURL(file);
           }
    } 
    function show()
    {
       //以下即为完整客户端路径
       var file_img=document.getElementById("img"),
        iptfileupload = document.getElementById('iptfileupload') ;
       getPath(file_img,iptfileupload,file_img) ;
    }
    function submitPostForm()
    {
    	
    var titleLength = $("#EssayUser_title").val().length;
		var conentLength = $("#EssayUser_content").val().length;
		var iptfileupload = $("#iptfileupload").val();
		if (titleLength <= 0) {
			$('#message').html("<p>你好像还没填写标题哦 :)</p>");
			return false;
		}else if (titleLength < 2) {
			$('#message').html("<p>为了顺利通过审核，投稿文章的标题不能少于2个字 :) :)</p>");
			return false;
		}else if (conentLength <= 0) {
			$('#message').html("<p>你好像还没填写内容哦 :)</p>");
			return false;
		}else if (conentLength < 20) {
			$('#message').html("<p>为了顺利通过，文章的内容不能少于20个字 (:o:) </p>");
			return false;
		};
		if( $("#iptfileupload").val() == ''){
			// W.tips( '请为你的文章配一张喜欢的封面吧 :)');
			$('#message').html("<p>请为你的文章配一张喜欢的图片吧 :) </p>");
			return false;
		}
		var form = new FormData(document.getElementById("form_ft"));
		$.ajax({
			url:"{:U('Article/add')}",
			type:"post",
            data:form,
            processData:false,
            contentType:false,
          	success:function(data){
          		if (data == 1) {
                alert('异常错误,请重试');
              }else if (data == 2) {
                $('#message').html("对不起您上传的不是图片 :(");
                return false;
              }else{
                var res  = data.substr(0,1);
                var url  = data.substring(2); 
                if (res == 3) {
                  $('#message').html("恭喜发布成功 :)");
                   window.location.href = url;
                }else if (res == 4) {
                  $('#message').html("发布失败 :)" );
                  window.location.href = url;
                };
              }
          	}
		});
    }
</script> 
   </div> 
   <!-- 公共尾部 --> 
  	<include file="Base:foraet" />
   <!-- 公共尾部 --> 